#include<iostream>
#include<vector>
using namespace std;


class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target)
    {
        vector<int> path(matrix.size(), 0);
        for (int i = 0; i < path.size(); i++)
        {
            path[i] = matrix[i][0];
        }

        int k = 0;
        int left = 0, right = path.size() - 1;
        while (right > left)
        {
            int mid = left + (right - left) / 2;
            if (target>path[mid])
            {
                if (target < path[mid + 1])
                {
                    k = mid;
                    break;
                }
                else if(target==path[mid+1])
                {
                    k = mid + 1;
                    break;
                }
                else if (target > path[mid + 1])
                {
                    left = mid+1;
                }
            }
            else if(target==path[mid])
            {
                k = mid;
                break;
            }
            else
            {
                right = mid;
            }
            
        }


        int l = 0, r = matrix[0].size()-1;
        while (r >= l)
        {
            int mid = left + (right - left) / 2;
            if (matrix[k][mid] == target)
            {
                return true;
            }
            else if (matrix[k][mid] < target)
            {
                l = mid + 1;
            }
            else {
                r = mid;
            }
        }
        return false;
    }
};


int main()
{
    Solution A;
    vector<vector<int>> ret = { {1} };
    

    bool x= A.searchMatrix(ret, 1);
    cout << x << endl;

    return 0;
}